#include "FParticleSystem.h"

void FParticleSystem::ParticleSeeding() {

	int cnt=0;

	for (int x=0; x<numGrid[0]; x++) {
		for (int y=0; y<numGrid[1]; y++) {
			for (int z=0; z<numGrid[2]; z++) {
				pos[cnt] = Vector3(x, y, z) * gap;


				cnt++;
			}
		}
	}

}

void FParticleSystem::Simulation() {
	
	BT_PROFILE("FParticleSystemSimulation");

	float residualDt = timeStepSize;
	while (residualDt > 0.0f) {
		if (residualDt < maxSubTimeStepSize) dt = residualDt;
		else dt = maxSubTimeStepSize;
		residualDt -= dt;

		//simulation here


	}

}

void FParticleSystem::Advection() {

}




void FParticleSystem::Rendering_Grid() {
	
	BT_PROFILE("RenderParticles");

	glPushMatrix();
	glPushAttrib( GL_POLYGON_BIT ); // includes GL_CULL_FACE
	glDisable(GL_CULL_FACE); // draw from all sides
	glPointSize(3.0f);

	glTranslatef(SystemPos.x(), SystemPos.y(), SystemPos.z());
	glBegin(GL_POINTS);
	for (int i=0; i<numParticles; i++) {
		float c = min(1.0, d[i] / max_d);
		c = 1 - c;
		glColor3f(c, c, c);
		Vector3 position = pos[i];
		glVertex3f(position.x(), position.y(), position.z());
	}
	glEnd();

	glPopAttrib(); // GL_CULL_FACE
	glPopMatrix();
}